<script type="text/javascript">
    var id = '<?php echo $this->id?>';
    $("#genericProfile").validate({
        rules: {
            GP_FirstName: {
                required: true
            },
            GP_LastName: {
                required: true
            },
            GP_Email: {
                email: true,
                remote: {
                    url: "<?php echo $this->baseUrl?>/users/index/user-exists/id/" + id,
                    type: "post"
                }
            },
            GP_Password: {

            },
            passwordConfirmation: {
                equalTo: '#GP_Password'
            }
        },
        messages: {
            GP_Email: {
                email: "Adresse invalide",
                remote:"<?php echo $this->getCibleText('profile_message_email_already_exists') ?>"
//                remote:'Test'
            },
            passwordConfirmation: {
                equalTo: 'Les mots de passe ne sont pas identiques.'
            }
        }
    });
    $("#memberInfo").validate({
        rules: {
            MP_BirthDate: {
                required: true
            }
        },
        messages: {
            MP_BirthDate: {
                required: 'Champs requis'
            }
        }
    });

    $('#MP_BirthDate').live('change', function(){

         var now=new Date();
         var dateArray = $(this).val().split('-').reverse();

        if((now.getMonth()+1)>=dateArray[1])
        {
            if((now.getMonth()+1)==dateArray[1])
            {
                if(now.getDate()>=dateArray[2])
                {
                    var mois=(now.getMonth()+1)-dateArray[1];
                    var ans=now.getFullYear()-dateArray[0];
                }
                else
                {
                    mois=(12-dateArray[1])+(now.getMonth()+1);
                    ans=now.getFullYear()-dateArray[0]-1;
                }
            }
            else
            {
                mois=(now.getMonth()+1)-dateArray[1];
                ans=now.getFullYear()-dateArray[0];
            }
        }
        else
        {
            mois=(12-dateArray[1])+(now.getMonth()+1);
            ans=now.getFullYear()-dateArray[0]-1;
        }
            if(now.getDate()>dateArray[2])
        {
            var jours=now.getDate()-dateArray[2];
        }
        else
        {
            jours=(30-dateArray[2])+(now.getDate());
        }
        while(jours>30)
        {
            jours-=30;
            mois+=1;
        }
        while(mois>12)
        {
            mois-=12;
            ans+=1;
        }
        $('#MP_Age').val(ans);

    });

    $('#MP_CountryOrig').blur(function(){
        if ($('#MP_PassportBirthDate').val() == '')
            $('#MP_PassportBirthDate').val($('#MP_BirthDate').val());
        if ($('#MP_PassportFirstName').val() == '')
            $('#MP_PassportFirstName').val($('#GP_FirstName').val());
        if ($('#MP_PassportLastName').val() == '')
            $('#MP_PassportLastName').val($('#GP_LastName').val());
    });
    $('#MP_BirthDate').blur(function(){
        if ($('#MP_PassportBirthDate').val() != '' && $('#MP_PassportBirthDate').val() != $('#MP_BirthDate').val())
            $('#MP_PassportBirthDate').val($('#MP_BirthDate').val());
    });

</script>
